package com.han.elasticsearch.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.han.elasticsearch.entity.ElasticSearchUser;
import com.han.elasticsearch.kafka.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author hanjl
 * @Description kafka控制器
 * @ClassName KafkaController
 * @createTime 2021/12/23 10:54
 */
@RestController
public class KafkaController {

    @Autowired
    private KafkaProducer kafkaProducer;

    @GetMapping("/single")
    public void sendSingle(){
        List<ElasticSearchUser> message = new ArrayList<>();
        ElasticSearchUser user = new ElasticSearchUser(9,"娱乐类",25, LocalDate.now(),"发送消息1");
        ElasticSearchUser user2 = new ElasticSearchUser(11,"天天",33, LocalDate.now(),"发送消息2");
        ElasticSearchUser user3 = new ElasticSearchUser(23,"小欧怕你",45, LocalDate.now(),"发送消息3");
        message.add(user);
        message.add(user2);
        message.add(user3);
        kafkaProducer.sendMessage(message,"kafka-user2");
    }

    @GetMapping("/kafka")
    public void send(){
        List<ElasticSearchUser> message = new ArrayList<>();
        ElasticSearchUser user = new ElasticSearchUser(1,"韩佳乐",25, LocalDate.now(),"发送消息1");
        ElasticSearchUser user2 = new ElasticSearchUser(2,"王虞姬",33, LocalDate.now(),"发送消息2");
        ElasticSearchUser user3 = new ElasticSearchUser(3,"王力宏",45, LocalDate.now(),"发送消息3");
        message.add(user);
        message.add(user2);
        message.add(user3);
        kafkaProducer.sendMessage(message,"kafka-user");
    }
    @GetMapping("/kafka1")
    public void sendCallBack(){
        List<ElasticSearchUser> message = new ArrayList<>();
        ElasticSearchUser user = new ElasticSearchUser(4,"天天",25, LocalDate.now(),"发送消息1");
        ElasticSearchUser user2 = new ElasticSearchUser(5,"王虞姬",33, LocalDate.now(),"发送消息2");
        ElasticSearchUser user3 = new ElasticSearchUser(6,"王力宏",45, LocalDate.now(),"发送消息3");
        message.add(user);
        message.add(user2);
        message.add(user3);
        kafkaProducer.sendMessageCallBack(message,"kafka-user");
    }
    @GetMapping("/kafka2")
    public void sendCallBack2(){
        List<ElasticSearchUser> message = new ArrayList<>();
        ElasticSearchUser user = new ElasticSearchUser(1,"韩佳乐",25, LocalDate.now(),"发送消息1");
        ElasticSearchUser user2 = new ElasticSearchUser(2,"王虞姬",33, LocalDate.now(),"发送消息2");
        ElasticSearchUser user3 = new ElasticSearchUser(3,"王力宏",45, LocalDate.now(),"发送消息3");
        message.add(user);
        message.add(user2);
        message.add(user3);
        kafkaProducer.sendMessageCallBack2(message,"kafka-user");
    }
}
